package com.mcy.springbatch.reader;

import com.mcy.springbatch.entity.SysUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.item.json.JacksonJsonObjectReader;
import org.springframework.batch.item.json.JsonItemReader;
import org.springframework.batch.item.json.builder.JsonItemReaderBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.FileSystemResource;

/**
 * 利用JsonItemReader从文件读取json数据，springbatch-4.1开始支持
 * @author : Create By mcy
 * @date : 2019/8/25 21:31:34
 */
@Slf4j
@Configuration
public class ReadUserDataJsonItemReader {

    @Bean
    public JsonItemReader<SysUser> userDataJsonItemReader(){
        return new JsonItemReaderBuilder<SysUser>()
                .jsonObjectReader(new JacksonJsonObjectReader<>(SysUser.class))
                .name("jsonItemReader")
                .resource(new FileSystemResource("/Users/calon/Desktop/userdata.json"))
                .saveState(true)
                .build();
    }

}
